//
//  SmsCloudPhoneController.m
//  smsCloud
//
//  Created by 吴斌 on 2024/7/20.
//

#import "SmsCloudPhoneController.h"
#import "SmsCloudCityController.h"
#import "SmsCloudRecordController.h"
#import "SmsCloudMainNavView.h"
#import "SmsCloudPhoneView.h"
#import "SmsCloudCityView.h"
#import "SmsCloudPhoneAlertView.h"
#import "SmsCloudPhoneBottomView.h"
#import "SmsCloudPhoneAlertPopUpView.h"
@interface SmsCloudPhoneController ()
@property (nonatomic,strong) SmsCloudMainNavView *smsCloudSearchNavView;
@property (nonatomic, strong)SmsCloudPhoneView * smsCloudPhoneView;
@property (nonatomic, strong)SmsCloudCityView * smsCloudCityView;
@property (nonatomic, strong)SmsCloudPhoneAlertView * smsCloudPhoneAlertView;
@property (nonatomic, strong)SmsCloudPhoneBottomView * smsCloudPhoneBottomView;

@property (nonatomic, strong)SmsCloudCityModel * smsCloudCityMdl;
@end

@implementation SmsCloudPhoneController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [SmsCloudHead SmsCloudColorHexString:@"#FFFFFF"];
    [self smsCloudInitView];
}
- (SmsCloudMainNavView *)smsCloudSearchNavView{
    if(!_smsCloudSearchNavView){
        __weak __typeof__(self) weakSelf = self;
        _smsCloudSearchNavView = [[SmsCloudMainNavView alloc] init];
        _smsCloudSearchNavView.backgroundColor = [SmsCloudHead SmsCloudColorHexString:@"#FFFFFF"];
        _smsCloudSearchNavView.smsCloudNavTitle = @"获取手机号";
        _smsCloudSearchNavView.SmsCloudMainBackBlock = ^{
            [weakSelf.navigationController popViewControllerAnimated:true];
        };
    }
    return _smsCloudSearchNavView;
}
- (SmsCloudPhoneView *)smsCloudPhoneView{
    if(!_smsCloudPhoneView){
        _smsCloudPhoneView = [[SmsCloudPhoneView alloc] init];
        _smsCloudPhoneView.smsCloudProductMdl = _smsCloudProductMdl;
    }
    return _smsCloudPhoneView;
}
- (SmsCloudCityView *)smsCloudCityView{
    if(!_smsCloudCityView){
        __weak __typeof__(self) weakSelf = self;
        _smsCloudCityView = [[SmsCloudCityView alloc] init];
        _smsCloudCityView.SmsCloudSelectCityBlock = ^{
            SmsCloudCityController *smsCloudCityCtrl = [[SmsCloudCityController alloc] init];
            [weakSelf.navigationController pushViewController:smsCloudCityCtrl animated:true];
            smsCloudCityCtrl.SmsCloudCityBlock = ^(SmsCloudCityModel * _Nonnull smsCloudCityMdl) {
                weakSelf.smsCloudCityMdl = smsCloudCityMdl;
                weakSelf.smsCloudCityView.smsCloudCityMdl = smsCloudCityMdl;
            };
        };
    }
    return _smsCloudCityView;
}
- (SmsCloudPhoneAlertView *)smsCloudPhoneAlertView{
    if(!_smsCloudPhoneAlertView){
        _smsCloudPhoneAlertView = [[SmsCloudPhoneAlertView alloc] init];
    }
    return _smsCloudPhoneAlertView;
}
- (SmsCloudPhoneBottomView *)smsCloudPhoneBottomView{
    if(!_smsCloudPhoneBottomView){
        __weak __typeof__(self) weakSelf = self;
        _smsCloudPhoneBottomView = [[SmsCloudPhoneBottomView alloc] init];
        _smsCloudPhoneBottomView.SmsCloudPhoneBlock = ^{
            [SmsCloudPhoneAlertPopUpView showSmsCloudPhoneAlertPopUp:weakSelf.view withCity:weakSelf.smsCloudCityMdl withProduct:weakSelf.smsCloudProductMdl withComplaint:^{
                SmsCloudRecordController * smsCloudRecordCtrl = [[SmsCloudRecordController alloc] init];
                [weakSelf.navigationController pushViewController:smsCloudRecordCtrl animated:true];
            }];
        };
        _smsCloudPhoneBottomView.SmsCloudPhoneRecordBlock = ^{
            SmsCloudRecordController * smsCloudRecordCtrl = [[SmsCloudRecordController alloc] init];
            [weakSelf.navigationController pushViewController:smsCloudRecordCtrl animated:true];
        };
    }
    return _smsCloudPhoneBottomView;
}
- (void)smsCloudInitView{
    [self.view addSubview:self.smsCloudSearchNavView];
    [self.view addSubview:self.smsCloudPhoneView];
    [self.view addSubview:self.smsCloudCityView];
    [self.view addSubview:self.smsCloudPhoneAlertView];
    [self.view addSubview:self.smsCloudPhoneBottomView];

    [self.smsCloudSearchNavView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:88] + [SmsCloudHead SmsCloudTopSafeH]));
    }];
    [self.smsCloudPhoneView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(self.smsCloudSearchNavView.mas_bottom);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:338]));
    }];
    [self.smsCloudCityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(self.smsCloudPhoneView.mas_bottom);
        make.height.equalTo(@([SmsCloudHead SmsCloudScreewRatio:241]));
    }];
    [self.smsCloudPhoneAlertView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(self.smsCloudCityView.mas_bottom);
        make.bottom.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:167]));
    }];
    [self.smsCloudPhoneBottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.right.equalTo(@([SmsCloudHead SmsCloudScreewRatio:0]));
        make.top.equalTo(self.smsCloudPhoneAlertView.mas_bottom);
        make.bottom.equalTo(@(-[SmsCloudHead SmsCloudScreewRatio:0]));
    }];
    [self requestSmsCloudCity];
}
- (void)requestSmsCloudCity{
    if (self.smsCloudProductMdl.code.length > 0) {
        __weak __typeof__(self) weakSelf = self;
        [SmsCloudDataHelper requestSmsCloudCity:self.smsCloudProductMdl.code scuessBlock:^{
            weakSelf.smsCloudCityMdl = [SmsCloudDataHelper defaultMag].smsCloudCitys.firstObject;
            weakSelf.smsCloudCityView.smsCloudCityMdl = [SmsCloudDataHelper defaultMag].smsCloudCitys.firstObject;
        }];
    }
}
@end
